#include <xp/net/inet.h>
#include <xp/bas/stdio.h>
#include <xp/bas/string.h>

int xp_main (int argc, xp_char_t* argv[])
{
	xp_uint32_t ip, ip2;
	xp_char_t buf[32];
	xp_size_t len;

	if (argc != 2) {
		xp_printf (XP_TEXT("%s: ip_address\n"), argv[0]);
		return -1;
	}	

	if (xp_inet4_strxtoip (argv[1], xp_strlen(argv[1]), &ip2) == -1) {
		xp_printf (XP_TEXT("strxtoip [%s] - not a valid address\n"), argv[1]);
		return -1;
	}

	if (xp_inet4_strtoip (argv[1], &ip) == -1) {
		xp_printf (XP_TEXT("strtoip [%s] - not a valid address\n"), argv[1]);
		return -1;
	}

	if (ip != ip2) {
		xp_printf (XP_TEXT("strtoip and strxtoip return different values\n"));
		return -1;
	}

	len = xp_inet4_iptostrx (ip, buf, xp_countof(buf));
	xp_printf (XP_TEXT("[%s] is valid. its length is %lu\n"), 
		buf, (unsigned long)len);

	return 0;
}
